package com.ruoyi.oar.controller.sys;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.oar.domain.dto.OarSmsDTO;
import com.ruoyi.oar.domain.query.OarSmsQuery;
import com.ruoyi.oar.service.OarSmsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;

/**
 * 短信日志Controller
 * 
 * @author oar
 * @date 2022-02-24
 */
@Api(tags = "短信日志")
@RestController
@RequestMapping("/sys/oar-sms")
public class OarSmsController extends BaseController
{
    @Autowired
    private OarSmsService oarSmsService;

    /**
     * 查询短信日志列表
     */
    @ApiOperation("查询短信日志列表")
    @PreAuthorize("@ss.hasRole('admin')")
    @GetMapping
    public TableDataInfo<OarSmsDTO> list(OarSmsQuery oarSmsQuery){
        logger.debug("查询短信日志列表,查询条件oarSmsQuery={}",JSONObject.toJSONString(oarSmsQuery));
        startPage();
        return oarSmsService.findAll(oarSmsQuery);
    }
    /**
     * 校验
     * @param id
     */
    private void checkId(String id) {
        Optional.ofNullable(id).orElseThrow(() -> new ServiceException("ID不能为空"));
        oarSmsService.selectOarSmsById(id).orElseThrow(() -> new ServiceException("无效的ID"));
    }
}
